//
//  NSString+Other.h
//  WeiChat
//
//  Created by   清正 on 15/10/20.
//  Copyright (c) 2015年 Personal. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>

///判断字符串是否为空
static inline BOOL isStringEmpty(NSString *value) {
    value =[NSString stringWithFormat:@"%@", value];
    BOOL result = FALSE;
    if (!value || [value isKindOfClass:[NSNull class]] ||[value isEqualToString:@"null"] ||[value isEqualToString:@"(null)"] ||[value isEqualToString:@"nil"] ||[value isEqualToString:@"<null>"]) {
        result = TRUE;
    } else {
        NSString *trimedString = [value stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
        if ([value isKindOfClass:[NSString class]] && [trimedString length] == 0) {
            result = TRUE;
        }
    }
    return result;
}

/// 处理合理字符串
static inline NSString* stringEmpty(NSString *value) {
    value =[NSString stringWithFormat:@"%@", value];
    NSString *result = @"";
    if (!value || [value isKindOfClass:[NSNull class]] ||[value isEqualToString:@"null"] ||[value isEqualToString:@"(null)"] ||[value isEqualToString:@"nil"] ||[value isEqualToString:@"<null>"]) {
        result = @"";
    } else {
        NSString *trimedString = [value stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
        result =trimedString;
        
        if ([value isKindOfClass:[NSString class]] && [trimedString length] == 0) {
            result = @"";
        }
    }
    return result;
}


@interface NSString (Other)
/**
 *  fond:字号
 */
- (CGFloat)stringOfSize:(CGFloat)fondSize;
- (CGSize)stringWithFont:(UIFont*)font;
/**
 *  第一个参数:字号大小
 *  第二个参数:定宽
 */
- (CGSize)stringOfFondSize:(CGFloat)fondSize aWidth:(CGFloat)width;

/**  文字转为图片
 *  arrContent:装字符串(每一项分为一段落)
 *  fontSize:字号
 *  color:字体颜色
 *  width:每行最大宽度
 */
+ (UIImage *)imageFromText:(NSArray*)arrContent withFont:(CGFloat)fontSize aTextColor:(UIColor*)color aWidth:(CGFloat)width;

/**
 *  用于表单上传多张图片
 *
 *  @param imageArray 图片数组
 *
 *  @return (此操作比较耗时,会阻塞主线程,建议在分线程中执行)
 */
+ (NSString *)getStringWithBase64ImageData:(NSMutableArray <UIImage*> *)imageArray;

/**
 *  32位小写 md5 加密
 */
- (NSString *)md5;
/**
 *  32位大写 MD5 加密
 */
- (NSString *)MD5;
/**
 *  字符串(2015-06-25 17:04)转date
 */
- (NSDate *)stringWithFormatDate:(NSString*)formatDate;
/**
 *  date转字符串
 */
+ (NSString *)dateWithString:(NSDate *)date format:(NSString*)formatDate;


/// 邮箱
- (BOOL)validateEmail;
/// 手机号码验证
- (BOOL)validateMobile;
/// 省份证号验证
- (BOOL)isValidateIDCard;
/// 车牌号验证
- (BOOL)isValidateCarNo;
/// 验证银行卡是否合法
- (BOOL)checkBankCardNumber;
/// 时间处理 (几分钟之前)
+ (NSString *)compareCurrentTime:(NSString *)timeStr;
/// 去除HTML标签对
- (NSString *)trimmedStringWithSpecialString;

// 获取
+ (id)getUserDefault:(NSString *)userMessage;
// 插入
+ (void)insertUserDefault:(id)userMessage key:(NSString *)key;
// 删除
+ (void)removeObjectForKey:(NSString *)key;

/**
 *  判断是否含有表情符
 *
 *  字符串
 *
 *  @return YES/NO
 */
- (BOOL)isContainsEmoji;

/**
 *  是否为中文
 *
 */
-(BOOL)isChinese;

/**
 *  转换字符串成拼音
 *  不支持多音字
 *  @return 返回字符串对应的拼音
 */
- (NSString *)transformToPinyin;


@end
